package cn.shyouchi.wuguanjia.android.ui.event.handover;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.utils.LogUtil;

/**
 * Created by Eenie on 2016/10/27 at 10:17
 * Email: 472279981@qq.com
 * Des:
 */

public class HandoverPhotoAdapter extends BaseQuickAdapter<HandoverPhotoEntity,BaseViewHolder> {
    AddHandoverContract.View mView;

    public HandoverPhotoAdapter(List<HandoverPhotoEntity> data, AddHandoverContract.View view) {
        super(R.layout.item_handover_photo_layout, data);
        this.mView = view;
    }

    @Override
    protected void convert(BaseViewHolder holder, final HandoverPhotoEntity entity) {
        ImageView imgHandover = holder.getView(R.id.img_handover);
        if (entity.getType() == HandoverPhotoEntity.PHOTO_TYPE_FLAG) {
            imgHandover.setImageResource(R.mipmap.ic_handover_toke_photo_flag);
        } else {
            bindImg(mContext, entity.getPath(), imgHandover);
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mView.infoItemClick(entity);
            }
        });
    }


    public List<HandoverPhotoEntity> getPhotos() {
        List<HandoverPhotoEntity> photoEntities = new ArrayList<>();
        photoEntities.addAll(getData());
        photoEntities.remove(photoEntities.size()-1);
        return photoEntities;
    }


    public void bindImg(Context context, String path, ImageView iv) {

        LogUtil.e(path);

        Glide.with(context)
                .load(path)
                .fitCenter()
                .into(iv);
    }
}
